package com.sugon.modules.kpi.service.impl;

import com.sugon.dao.ErmsKpiDeviceDao;
import com.sugon.dao.ErmsKpiLineDao;
import com.sugon.dao.ErmsKpiWorkshopDao;
import com.sugon.entity.ErmsKpiDeviceEntity;
import com.sugon.entity.ErmsKpiLineEntity;
import com.sugon.entity.ErmsKpiWorkshopEntity;
import com.sugon.modules.kpi.service.IErmsKpiManager;
import com.sugon.service.ErmsKpiDeviceService;
import com.sugon.service.ErmsKpiLineService;
import com.sugon.service.ErmsKpiWorkshopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ： YuXD
 * @description：
 * @date ： 2021-03-24 下午 7:15
 * @version: 1.0
 */
@Service
public class ErmsKpiManagerImpl implements IErmsKpiManager {

    @Autowired
    private ErmsKpiWorkshopService kpiWorkshopService;
    @Autowired
    private ErmsKpiLineService kpiLineService;
    @Autowired
    private ErmsKpiDeviceService kpiDeviceService;
    @Autowired
    private ErmsKpiWorkshopDao ermsKpiWorkshopDao;
    @Autowired
    private ErmsKpiLineDao ermsKpiLineDao;
    @Autowired
    private ErmsKpiDeviceDao ermsKpiDeviceDao;

    @Override
    public boolean deleteKpiDataByYearly(Integer yearly) {
        ermsKpiWorkshopDao.deleteByYearly(yearly);
        ermsKpiLineDao.deleteByYearly(yearly);
        ermsKpiDeviceDao.deleteByYearly(yearly);
        return true;
    }

    @Override
    public boolean saveKpiComputeResult(Integer level, String organizationId, String target, String monthly, Double value) {
        int rows;
        if (level <= 2) {
            rows = kpiWorkshopService.save(new ErmsKpiWorkshopEntity(organizationId, target, monthly, value));
        } else if (level == 3) {
            rows = kpiLineService.save(new ErmsKpiLineEntity(organizationId, target, monthly, value));
        } else {
            rows = kpiDeviceService.save(new ErmsKpiDeviceEntity(organizationId, target, monthly, value));
        }
        return rows > 0;
    }

}
